﻿package frEngine.shader.filters.vertexFilters
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import baseEngine.system.*;
    import frEngine.animateControler.particleControler.*;
    import frEngine.animateControler.particleControler.animate.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.*;
    import frEngine.shader.filters.vertexFilters.def.*;
    import frEngine.shader.registType.*;

    public class ParticleVertexFilter_CPU extends ParticleVertexFilter
    {
        private var time_perEmitterTime_emitterLife:Vector.<Number>;
        private var _uvStep:Vector.<Number>;
        private var _useColorOrAlpha:Vector.<Number>;
        private var _faceCameraConst:Vector.<Number>;

        public function ParticleVertexFilter_CPU(param1:ParticleFileData = null)
        {
            this.time_perEmitterTime_emitterLife = this.Vector.<Number>([0, 1, 60, 2]);
            this._uvStep = this.Vector.<Number>([1, 1, -1, -1]);
            this._useColorOrAlpha = this.Vector.<Number>([0, 0, 0.25, 0.75]);
            this._faceCameraConst = this.Vector.<Number>([0, 1, -1, -1]);
            super(param1);
            return;
        }// end function

        override public function setRegisterParams(param1:Program3dRegisterInstance) : void
        {
            var _loc_2:* = particleFileData.particleParams;
            param1.getParamByName("{faceCameraConst}", true).value = this._faceCameraConst;
            if (_loc_2.useColor || _loc_2.useAlpha)
            {
                param1.getParamByName("{useColorOrAlpha}", false).value = this._useColorOrAlpha;
            }
            var _loc_3:* = param1.getParamByName("{uvStep}", false);
            var _loc_4:* = this._uvStep;
            _loc_3.value = this._uvStep;
            param1.getParamByName("{time_perEmitterTime_emitterLife}", true).value = this.time_perEmitterTime_emitterLife;
            return;
        }// end function

        override public function get programeId() : String
        {
            var _loc_1:* = particleFileData.particleParams;
            var _loc_2:String = "pc:";
            var _loc_3:* = _loc_2 + "2";
            _loc_2 = _loc_2 + "2";
            return _loc_2;
        }// end function

        override public function createVertexCode(param1:Program3dRegisterInstance, param2:int) : String
        {
            param1.OpType = ECalculateOpType.ViewProj;
            var _loc_3:Array = [];
            var _loc_4:int = 0;
            _loc_3.push(new ToBuilderInfo("va0", FilterName.POSITION, false, 4));
            _loc_3.push(new ToBuilderInfo("vc0-100", "{vc0-100}", false, ParticleParams.maxConstRegistNum));
            _loc_3.push(new ToBuilderInfo("vc1", "{_const1}", false, 1, [ParticleStatus.multyply0, ParticleStatus.multyply1, ParticleStatus.multyply2, ParticleStatus.multyply3]));
            _loc_3.push(new ToBuilderInfo("vm0", "{faceCameraMatrix}", false, 4, Device3D.faceCameraMatrix3d));
            _loc_3.push(new ToBuilderInfo("vc2", "{faceCameraConst}", false, 1, this._faceCameraConst));
            _loc_3.push(new ToBuilderInfo("vc4", "{globalSize}", false, 1, []));
            _loc_3.push(new ToBuilderInfo("vc3", "{time_perEmitterTime_emitterLife}", false, 1, this.time_perEmitterTime_emitterLife));
            _loc_3.push(new ToBuilderInfo("va1", FilterName.PARAM0, false, 4));
            _loc_3.push(new ToBuilderInfo("vf3", "{V_ParticleUV}", false, 1));
            _loc_3.push(new ToBuilderInfo("vf2", "{v_param0}", false, 1));
            var _loc_5:String = "";
            _loc_5 = _loc_5 + "mul \t\t \t vt4.x \t\t\t\tva0.w \t\t\t\tvc3.w\t\t\t\t\n";
            _loc_5 = _loc_5 + "add \t\t \t vt4.y \t\t\t\tvt4.x \t\t\t\t{vcConst1}.z\t\t\n";
            _loc_5 = _loc_5 + "mov           vt3      \t \t\tvc[vt4.y]           \t\t\t\t\t\n";
            _loc_5 = _loc_5 + "div \t\t \t vt1 \t\t\t\tvt3 \t\t\t\t{_const1}.x\t\t    \n";
            _loc_5 = _loc_5 + "frc \t\t \t vt2 \t\t\t \tvt1\t\t\t\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "mul \t\t \t vt6 \t\t\t\tvt2 \t\t\t\t{_const1}.x\t\t    \n";
            _loc_5 = _loc_5 + "sub \t\t \t vt6 \t\t\t\tvt6 \t\t\t\t{vcConst1}.z\t\t\n";
            _loc_5 = _loc_5 + "sub \t\t \t vt2 \t\t\t\tvt1 \t\t\t\tvt2\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "div \t\t  {output}.w\t\t\t\tvt2.w \t\t\t{_const1}.z\t        \n";
            _loc_5 = _loc_5 + "mov \t\t     vf3 \t\t\t\t{output}.w \t\t\t\t\t\t        \n";
            _loc_5 = _loc_5 + "mov \t\tvt1.xyz \t\t\t\t\tvc4.xyz\t\t\t\n";
            _loc_5 = _loc_5 + "mov \t\tvt3.xyzw\t\t\tvt6.wzyx\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "mov \t\tvt4.xyzw\t\t\tvt6.zwxy\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "mov \t\tvt5.xyzw\t\t\tvt6.yxwz\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "neg \t\tvt3.y\t\t\t\tvt3.y\t\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "neg \t\tvt4.z\t\t\t\tvt4.z\t\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "neg \t\tvt5.x\t\t\t\tvt5.x\t\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "mul \t\tvt1.xyz\t\t\t\tvt1.xyz\t\t\t\tva0.xyz\t\t\t\n";
            _loc_5 = _loc_5 + "mov \t\tvt1.w\t\t\t\t{vcConst1}.x\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "m44 \t\tvt1\t\t\t\t\tvt1\t\t\t\t\tvt3\t\t\t\t\n";
            _loc_5 = _loc_5 + "m44 \t\tvt1 \t\t\t\tvt1\t\t\t\t\tvt3\t\t\t\t\n";
            _loc_5 = _loc_5 + "m33 \t\t{output}.xyz \t\tvt1.xyz\t\t\t\tvm0 \t\t\t\n";
            _loc_5 = _loc_5 + "mul \t\t{output}.xyz \t\t{output}.xyz \t\t{faceCameraConst}.x\t\n";
            _loc_5 = _loc_5 + "mul \t\t vt1.xyz \t\t\tvt1.xyz\t\t\t\t{faceCameraConst}.y \t\n";
            _loc_5 = _loc_5 + "add \t\t{output}.xyz \t\tvt1.xyz \t\t\t{output}.xyz\t\n";
            _loc_5 = _loc_5 + "div \t\tvt2.xyz \t\t\tvt2.xyz \t\t\t{_const1}.w\t\n";
            _loc_5 = _loc_5 + "mul \t\t \t vt4.x \t\t\t\tva0.w \t\t\t\tvc3.w\t\t\t\t\n";
            _loc_5 = _loc_5 + "mov           vt3      \t \t\tvc[vt4.x]           \t\t\t\t\t\n";
            _loc_5 = _loc_5 + "div \t\t \t vt3 \t\t\t\tvt3\t\t\t\t{_const1}.x\t\t\n";
            _loc_5 = _loc_5 + "frc \t\t \t vt4 \t\t\t \tvt3\t\t\t\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "mul \t\t \t vt5 \t\t\t\tvt4\t\t\t\t{_const1}.x\t\t\n";
            _loc_5 = _loc_5 + "sub \t\t \t vt6 \t\t\t\tvt5\t\t\t\t{vcConst1}.z\t\t\n";
            _loc_5 = _loc_5 + "mul         {output}.xyz         {output}.xyz        vt6.www        \n";
            _loc_5 = _loc_5 + "add \t\t   {output}.xyz \t\t{output}.xyz \t\tvt2.xyz\t\t\t\n";
            _loc_5 = _loc_5 + "sub           vt2                 vt3                 vt4             \n";
            _loc_5 = _loc_5 + "div \t\t \t vf3.x  \t\t\tvt2.w\t\t\t    {_const1}.z\t        \n";
            _loc_5 = _loc_5 + "dp3           vt3.x              vt6.xyz              vt6.xyz             \n";
            _loc_5 = _loc_5 + "sub           vt3.x            {vcConst1}.z            vt3.x              \n";
            _loc_5 = _loc_5 + "sqt           vt6.w              vt3.x                                    \n";
            _loc_5 = _loc_5 + "mov \t\t    vt3.xyzw\t\t\tvt6.wzyx\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "mov \t\t    vt4.xyzw\t\t\tvt6.zwxy\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "mov \t\t    vt5.xyzw\t\t\tvt6.yxwz\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "neg \t\t    vt3.y\t\t\t\tvt3.y\t\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "neg \t\t    vt4.z\t\t\t\tvt4.z\t\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "neg \t\t    vt5.x\t\t\t\tvt5.x\t\t\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "div \t\tvt2.xyz \t\t\tvt2.xyz \t\t\t{_const1}.w\t\n";
            _loc_5 = _loc_5 + "mul     vt1.xyz      \t \tvt2.xyz\t\t\t\tvc4.xyz       \n";
            _loc_5 = _loc_5 + "mov \t\tvt1.w\t\t\t\t{vcConst1}.x\t\t\t\t\t\t\n";
            _loc_5 = _loc_5 + "m44 \t\tvt1\t\t\t\t\tvt1\t\t\t\t\tvt3\t\t\t\t\n";
            _loc_5 = _loc_5 + "m44 \t\tvt1 \t\t\t\tvt1\t\t\t\t\tvt3\t\t\t\t\n";
            _loc_5 = _loc_5 + "add \t\t{output}.xyz \t\tvt1.xyz \t\t\t{output}.xyz\t\n";
            _loc_5 = _loc_5 + "mov     {output}.w      \t{vcConst1}.z  \t\t \t \t\t\t\n";
            _loc_5 = _loc_5 + "mov           vf2      \t\tva1  \t\t \t \t\t\t\t\n";
            _loc_5 = _loc_5 + "mul           vt0.x      \t\t vc3.y\t\t\t\tva1.x           \t\t\t\n";
            _loc_5 = _loc_5 + "sub           vt0.x      \t\t vc3.x\t\t\t\tvt0.x           \t\t\t\n";
            _loc_5 = _loc_5 + "div           vt0.y      \t\t vt0.x\t\t\t\tvc3.z           \t\t\t\n";
            _loc_5 = _loc_5 + "frc           vt0.z      \t\t vt0.y\t\t\t\t           \t\t\t\t\n";
            _loc_5 = _loc_5 + "sub           vt0.w      \t\t vt0.y\t\t\t\tvt0.z           \t\t\t\n";
            _loc_5 = _loc_5 + "mul           vf2.x      \t\t vt0.z\t\t\t\tvc3.z           \t\t\t\n";
            _loc_5 = param1.toBuild(_loc_5, _loc_3);
            return _loc_5;
        }// end function

        override public function preCreateFragmentUvCoord(param1:Program3dRegisterInstance) : String
        {
            var _loc_2:String = "";
            var _loc_3:* = param1.getParamByName(FilterName.F_UVPostion, false);
            if (!_loc_3)
            {
                return _loc_2;
            }
            var _loc_4:Array = [];
            _loc_4.push(new ToBuilderInfo("fc1", "{uvStep}", false, 1, this._uvStep));
            _loc_2 = _loc_2 + "mul           {F_UVPostion}.xy        {F_UVPostion}.xy      fc1.xy  \t\t\t\t\n";
            _loc_2 = _loc_2 + "add           {F_UVPostion}.xy        {F_UVPostion}.xy      {V_ParticleUV}.xy  \t\n";
            _loc_2 = param1.toBuild(_loc_2, _loc_4);
            return _loc_2;
        }// end function

        override public function createFragmentColor(param1:Program3dRegisterInstance, param2:Boolean) : String
        {
            var _loc_3:* = particleFileData.particleParams;
            var _loc_4:String = "";
            var _loc_5:* = _loc_3.useColor ? (1) : (0);
            var _loc_6:* = _loc_3.useAlpha ? (1) : (0);
            if (!_loc_5 && !_loc_6)
            {
                return "";
            }
            var _loc_7:Array = [];
            _loc_4 = _loc_4 + "mul           {output}      {output}  \t\t {v_param0}.w\t\t\t\t\t\t\n";
            var _loc_8:* = ParticleFileData.defaultParticleTextue;
            var _loc_9:* = 1 / ParticleParams.bitmapHeight;
            _loc_7.push(new ToBuilderInfo("fs0", "{dateaTexture}", false, 1, _loc_8));
            _loc_7.push(new ToBuilderInfo("fc1", "{fconst0}", false, 1, [_loc_9 * 0, _loc_9 * 1, _loc_9 * 2, _loc_9 * 3.5]));
            _loc_7.push(new ToBuilderInfo("fc2", "{useColorOrAlpha}", false, 1, this._useColorOrAlpha));
            _loc_4 = _loc_4 + "div           ft0.x        \t\t{v_param0}.x  \t\t \t\t{v_param0}.y \t\t\n";
            _loc_4 = _loc_4 + "sge           \tft0.z           \t{v_param0}.z    \t\t\t{fcConst1}.w\t\t\n";
            _loc_4 = _loc_4 + "slt           ft0.w           \t{v_param0}.z    \t\t\t{fcConst1}.w\t\t\n";
            _loc_4 = _loc_4 + "mul           ft2.x           \tfc1.x    \t\t\t \t\t\t\tft0.z      \t\t\n";
            _loc_4 = _loc_4 + "mul           ft2.y           \tfc1.y    \t\t\t \t\t\t\tft0.w      \t\t\n";
            _loc_4 = _loc_4 + "add           ft0.y           \tft2.x   \t\t\t \t\t\t\tft2.y      \t\t\n";
            _loc_4 = _loc_4 + "mov           ft3      \t\t\tfc2  \t\t  \t\t\t\t\t\t\t\t\t\t\t\n";
            _loc_4 = _loc_4 + "sub           ft4      \t\t\t{fcConst1}.z  \t\t  \t\t\t\tft3\t\t\t\t\t\n";
            _loc_4 = _loc_4 + ("tex           ft1           \t\tft0.xy    \t\t\t\t" + getSmapleString("fs0", _loc_8.format, false, _loc_8.mipMode, "nearest") + "\t\n");
            _loc_4 = _loc_4 + "mul           ft1      \t\t\tft1  \t\t  \t\t\tft3.x\t\t\t\t\t\t\t\t\n";
            _loc_4 = _loc_4 + "add           ft1      \t\t\tft1  \t\t  \t\t\tft4.xxxx\t\t\t\t\t\t\t\n";
            _loc_4 = _loc_4 + "mul           {output}.xyz      ft1  \t\t  \t\t\t{output}.xyz\t\t\t\t\t\t\n";
            _loc_4 = _loc_4 + "slt           \tft2.z           \t{v_param0}.z    \t\t\t\t{useColorOrAlpha}.z\t\n";
            _loc_4 = _loc_4 + "sge           ft2.w           \t{v_param0}.z    \t\t\t\t{useColorOrAlpha}.w    \n";
            _loc_4 = _loc_4 + "add           ft0.z           \tft2.z    \t\t\t\t\t\tft2.w      \t\n";
            _loc_4 = _loc_4 + "sub           ft0.w           \t{fcConst1}.z    \t\t\t\tft0.z      \t\n";
            _loc_4 = _loc_4 + "mul           ft1.x           \tfc1.z    \t\t\t \t\t\tft0.z      \t\n";
            _loc_4 = _loc_4 + "mul           ft2.x           \tfc1.w    \t\t\t \t\t\tft0.w      \t\n";
            _loc_4 = _loc_4 + "add           ft0.y           \tft1.x   \t\t\t \t\t\tft2.x      \t\n";
            _loc_4 = _loc_4 + ("tex           ft1           \t\tft0.xy    \t\t\t\t" + getSmapleString("fs0", _loc_8.format, false, _loc_8.mipMode, "nearest") + "\t\n");
            _loc_4 = _loc_4 + "mul           ft1      \t\t\tft1  \t\t  \t\t\t\t\tft3.y\t\t\t\n";
            _loc_4 = _loc_4 + "add           ft1      \t\t\tft1  \t\t  \t\t\t\t\tft4.yyyy\t\t\n";
            _loc_4 = _loc_4 + "mul           {output}      \t\tft1.x  \t\t  \t\t\t\t\t{output}\t\n";
            _loc_4 = param1.toBuild(_loc_4, _loc_7);
            return _loc_4;
        }// end function

        override public function dispose() : void
        {
            particleFileData = null;
            super.dispose();
            return;
        }// end function

    }
}
